package cn.edu.cxcyzx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cn.edu.cxcyzx.entity.AddStuApply;
import cn.edu.cxcyzx.entity.Datagrid;
import cn.edu.cxcyzx.entity.Student;
import cn.edu.cxcyzx.service.AddStuApplyService;
import cn.edu.cxcyzx.supervisor.DaoFit;
import cn.edu.cxcyzx.supervisor.ResultDo;

@Service("AddStuApplyService")
public class AddStuApplyServiceImpl implements AddStuApplyService{
	
	@Resource
	public DaoFit daoFit;
	
	public ResultDo<List<AddStuApply>> getAllAddStuApply(String stuName) {
		// TODO Auto-generated method stub
		ResultDo<List<AddStuApply>> resultDo=new ResultDo<>();
		List<AddStuApply> list=daoFit.getAddStuApplyDao().getAllApply(stuName);
		if(list!=null&&list.size()>0){
			resultDo.setSuccess(true);
			resultDo.setResult(list);
		}else{
			resultDo.setSuccess(false);
		}		
		return resultDo;
	}

	@Override
	public void updateState(int id,int state) {
		// TODO Auto-generated method stub
		if(state==1){
			AddStuApply stuApply= daoFit.getAddStuApplyDao().getApplyById(id);
			if(stuApply!=null){
				System.out.println("-=-=-=-=-"+stuApply.getStudent().toString());
				System.out.println("-----插入成功");
				Student stu=stuApply.getStudent();
				stu.setGroupId(stuApply.getGroupId());
				daoFit.getStudentDao().insertStu(stu);
			}
		}
		daoFit.getAddStuApplyDao().updateState(id,state);
	}

}
